package dk.netl.dashboard;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.lang.StringBuilder;

public class FileUtils {
    public function save(fileName: String, text: String): Void {
        if (text != null) {
            var output =
                    new OutputStreamWriter(new FileOutputStream(fileName), "UTF-8");
            output.write(text);
            output.close();
        }
    }

    public function load(fileName: String, text: String): String {
        def input = new BufferedReader(new InputStreamReader(new FileInputStream(fileName), "UTF-8"));
        def sb = new StringBuilder();
        var line : String;
        while((line = input.readLine()) != null) {
            sb.append(line).append("\n");
        }
        input.close();
        return sb.toString();
    }

}
